package au.com.handsunited.web.validator.organisation;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import au.com.handsunited.web.command.organisation.OrganisationSearchCommand;

/**
 * @author arunda
 *
 */
public class OrganisationSearchCommandValidator implements Validator {

	/**
	 *
	 */
	public OrganisationSearchCommandValidator() {
	}

	/**
	 * @see org.springframework.validation.Validator#supports(java.lang.Class)
	 */
	@Override
	public boolean supports(Class clazz) {
		return clazz.isAssignableFrom(OrganisationSearchCommand.class);
	}

	/**
	 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
	 */
	@Override
	public void validate(Object target, Errors errors) {

		OrganisationSearchCommand command = (OrganisationSearchCommand) target;

		//	We need at least one field filled in
//		if (StringUtils.isBlank(command.getOrganisation().getName()) && StringUtils.isBlank(command.getKeywords()) &&
//				StringUtils.isBlank(command.getOrganisation().getLocation().getSuburb()) &&
//				StringUtils.isBlank(command.getOrganisation().getLocation().getCity()) &&
//				StringUtils.isBlank(command.getOrganisation().getLocation().getState()) &&
//				command.getOrganisation().getServiceCategories().isEmpty()) {
//
//			errors.reject("", "At least one search field is required.");
//		}

	}

}
